import dialogForm from './edit'              //弹窗组件
import agentHttp from '@/utils/agentHttp'    //请求方法
import pagination from '@/views/pagination'  //分页组件
import {confirm} from '@/utils/confirm'      //二次确认组件
export default {
  name: 'hotBrands',
  components:{dialogForm,pagination},
  created(){
    this.seachData();
    this.allButton = buttonPermission('all');
    this.addButton= buttonPermission('add');
    this.updateButton= buttonPermission('update');
    this.viewButton= buttonPermission('view');
    this.disableButton= buttonPermission('disable');
  },
  data() {
    return {
      //表格字段
      tableData: [],
      //弹窗状态数据
      dialogSendData:{
        isAdd:"",
        dialogFormVisible:"",
        id:""
      },
      searchForm:{},
      resetFormStatus:false
    }
  },
  methods: {
    seachData(){
      if(!this.resetFormStatus){
        var params=this.searchForm||{};
        params.page=this.tableData.page||1;
        params.rows=this.tableData.rows||10;
        agentHttp.postJson('adminApi/admin/car_specification/list?page='+params.page+'&rows='+params.rows,params ).then((data)=>{
          if (data.success) {
            this.tableData = data.data.tableData;
          }
        })
      }
    },
    /*表格操作按钮*/
    //删除
    handleDisabled(index, row){
        var flag=this.$refs[('flag'+index)].$el.textContent;
        confirm(()=>{
          agentHttp.patch('adminApi/admin/car_specification/disable/'+row.id).then((data)=>{
            if(data.success){  
               this.$message.success(data.data||(flag+"成功"));
                this.seachData();
            } 
          })
        },()=>{
           this.$message.info('已取消'+flag); 
        },"确认"+flag+"该条数据吗?")
    },
    //新增、编辑
    handleEdit(index, row){
      row?this.dialogSendData.id=row.id:this.dialogSendData.id="";
      this.dialogSendData.isAdd=true;
      this.dialogSendData.dialogFormVisible=true;
    },
    //查看
    handleSee(index, row){
      row?this.dialogSendData.id=row.id:this.dialogSendData.id="";
      this.dialogSendData.isAdd=false;
      this.dialogSendData.dialogFormVisible=true;
    }
  }
}